﻿using Net5ApiANdWpfClient.Lib.Common;
using Net5ApiANdWpfClient.Lib.Model;
using Net5ApiANdWpfClient.Lib.Model.SystemAdmin;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Net5ApiANdWpfClient.Lib.Service
{
   public class positioninfoService
    {     
            /// <summary>
            /// 用户搜索方法
            /// </summary>
            /// <param name="po_name">职位</param>
            /// <param name="CurrentPageIndex">当前页</param>
            /// <returns></returns>
            public PagerResult<positioninfo> SearchPage(string po_name, int CurrentPageIndex)
            {
                string apiUrl = "api/Positioninfo/PositioninfoList"; //请求api的路径
                SearchModel search = new SearchModel()
                {
                    SearchItem = new Dictionary<string, string> { { "po_name", po_name } },
                    page = CurrentPageIndex,
                    limit = PcConfig.PageSize
                };
                ResultModel result = HttpRequestTools.PostByToken(apiUrl, JsonConvert.SerializeObject(search));
                if (result.code == ResultCode.Ok)
                {
                    return JsonConvert.DeserializeObject<PagerResult<positioninfo>>(JsonConvert.SerializeObject(result.data));
                }
                else
                {
                    return null;
                }

            }
        public bool positioninfodd(positioninfo info, out string mess)//信息添加
        {
            if (info == null)
            {
                mess = "数据错误!";
                return false;
            }
            string apiUrl = "api/Positioninfo/PositionInfoAdd"; //请求api的路径
            ResultModel result = HttpRequestTools.PostByToken(apiUrl, JsonConvert.SerializeObject(info));
            mess = result.mess;
            if (result.code == ResultCode.Ok)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        public bool positioninfoDel(int po_id)//删除方法
        {
            string apiUrl = "api/Positioninfo/PositionInfoDelete?po_id=" + po_id; //请求api的路径
            ResultModel result = HttpRequestTools.PostByToken(apiUrl);
            if(result.code==ResultCode.Ok)
            {
                return true;
            }
            return false;
        }
         
        public positioninfo positionUpdate(int po_id)//反填
        {
           string apiUrl = "api/Positioninfo/GetOutsourcePoID?po_id=" + po_id; //请求api的路径
            // string apiUrl = "api/Positioninfo/PositionInfoDelete"; //请求api的路径
            ResultModel result = HttpRequestTools.PostByToken(apiUrl);

            if (result.code == ResultCode.Ok)
            {
                var list= JsonConvert.DeserializeObject<positioninfo>(JsonConvert.SerializeObject(result.data));
                return list;
            }
            return null;
        }
        public bool PositioninfoPut(positioninfo info)//修改
        {
            string apiUrl = "api/Positioninfo/PositioninfoPut";//请求api的路径
          //string list = "{\"po_id\":\"" + info.po_id + "\",\"po_name\":\"" + info.po_name + "\",\"po_other_name\":" + info.po_other_name+ "}";
            ResultModel result = HttpRequestTools.PostByToken(apiUrl,JsonConvert.SerializeObject(info));
            if (result.code == ResultCode.Ok)
            {
                return true;
            }
            return false;
        }

    }


    }

